package cn.gjculture.shopping.api.controller;

import cn.gjculture.shopping.api.entity.PageInfo;
import cn.gjculture.shopping.api.entity.Return;
import cn.gjculture.shopping.api.entity.wx.PicTxtMessage;
import cn.gjculture.shopping.api.service.ServiceMessageService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping(value = "/serviceMessage")
public class ServiceMessageController {

    @Autowired
    ServiceMessageService serviceMessageService;

    @PostMapping
    public Return save(PicTxtMessage message) {
        Return ret = new Return();
        if(serviceMessageService.insert(message)>0){
            ret.getCommon().setRet(true);
        }
        return ret;

    }

    @GetMapping
    public Return<List<PicTxtMessage>> query(PicTxtMessage message, PageInfo pageInfo) {
        Return<List<PicTxtMessage>> ret = new Return<>();
        List<PicTxtMessage> picTxtMessages = serviceMessageService.query(message);
        ret.setData(picTxtMessages);
        return ret;
    }

    @GetMapping(value = "/{id}")
    public Return<PicTxtMessage> gitActivity(@PathVariable(value = "id") String id) {
        Return<PicTxtMessage> ret = new Return<>();
        PicTxtMessage picTxtMessage = serviceMessageService.queryById(id);
        ret.setData(picTxtMessage);
        return ret;
    }

    @DeleteMapping(value = "/{id}")
    public Return delete(@PathVariable(value = "id") String id) {
        Return ret = new Return<>();
        if(serviceMessageService.delete(id,ret)>0){
            ret.getCommon().setRet(true);
        }
        return ret;
    }

    @PostMapping(value = "/send/{id}")
    public Return send(@PathVariable(value = "id") String id){
        Return ret=new Return();
        serviceMessageService.send(id);
        return ret;
    }
}
